package com.example.hadoop.mapreduce.orderjoin;

import lombok.Data;
import org.apache.hadoop.io.Writable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: Brian
 * @Date: 2020/04/25/23:55
 * @Description:
 */
@Data
public class OrderInfoBean implements Writable {

    private String orderId;
    private String date;
    private String productId;
    private double amount;
    private boolean isOrderInfo;
    private String productName;
    private String categoryId;
    private double price;

     public void setOrderInfo(String orderId, String date, String productId, double amount) {
         this.orderId = orderId;
         this.date = date;
         this.productId = productId;
         this.amount = amount;
         this.isOrderInfo = true;
         this.productName = "";
         this.categoryId = "";
         this.price = 0;
     }

     public void setProductInfo(String productId, String productName, String categoryId, double price) {
         this.orderId = "";
         this.date = "";
         this.productId = productId;
         this.amount = 0;
         this.isOrderInfo = false;
         this.productName = productName;
         this.categoryId = categoryId;
         this.price = price;
     }

    @Override
    public void write(DataOutput out) throws IOException {
        out.writeUTF(orderId);
        out.writeUTF(date);
        out.writeUTF(productId);
        out.writeDouble(amount);
        out.writeBoolean(isOrderInfo);
        out.writeUTF(productName);
        out.writeUTF(categoryId);
        out.writeDouble(price);
    }

    @Override
    public void readFields(DataInput in) throws IOException {
        this.orderId = in.readUTF();
        this.date = in.readUTF();
        this.productId = in.readUTF();
        this.amount = in.readDouble();
        this.isOrderInfo = in.readBoolean();
        this.productName = in.readUTF();
        this.categoryId = in.readUTF();
        this.price = in.readDouble();
    }

    public String toString() {
         return "orderId: " + orderId + ", date:" + date + ", productId:" + productId + ", amount:" + amount + ",productName:" + productName + ",price:" + price;
    }
}
